﻿namespace WriterStars.Controllers
{
    using System.Web.Mvc;

    using WriterStars.Model;
    using WriterStars.Data;
    
    [RequireHttps]
    public class HomeController : Controller
    {
        private IWriterStarsData data;

        public HomeController()
        {
            this.data = new WriterStarsData(new WriterStarsDbContext());
        }

        public ActionResult Index()
        {
            return this.View();
        }

        public ActionResult About()
        {
            return View();
        }

        public ActionResult Contact()
        {
            return View();
        }

        public ActionResult UnderConstruction()
        {
            return this.View();
        }

        public ActionResult Subscribe()
        {
            return this.View();
        }

        public ActionResult Terms()
        {
            return this.View();
        }

        public ActionResult Academy()
        {
            return this.View();
        }


        [HttpPost]
        public ActionResult Subscribe(string email = "")
        {

            if (email != "")
            {
                
                var subscriber = new Subscriber
                {
                    Email = email
                };

                this.data.Subscribers.Create(subscriber);
                this.data.Subscribers.SaveChanges();

                this.ViewBag.Message = "Subscribed successfully";
            }

            return this.View();
        }

        //public ActionResult LoadMore(int id = 0)
        //{
        //    var currentUserId = this.User.Identity.GetUserId();

        //    var books = this.blogService.GetsuggestedBooks(currentUserId);

        //    var blogBooks = books.Skip((id - 1) * BooksPerPage).Take(BooksPerPage);

        //    return this.PartialView("_Books", blogBooks);
        //}
    }
}